<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>descriptor.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_proto2_descriptor.js.html">descriptor.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Protocol Buffer (Message) Descriptor class.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>goog.provide(&#39;goog.proto2.Descriptor&#39;);
<a name="line20"></a>goog.provide(&#39;goog.proto2.Metadata&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.array&#39;);
<a name="line23"></a>goog.require(&#39;goog.object&#39;);
<a name="line24"></a>goog.require(&#39;goog.proto2.Util&#39;);
<a name="line25"></a>
<a name="line26"></a>
<a name="line27"></a>/**
<a name="line28"></a> * @typedef {{name: (string|undefined),
<a name="line29"></a> *            fullName: (string|undefined),
<a name="line30"></a> *            containingType: (goog.proto2.Message|undefined)}}
<a name="line31"></a> */
<a name="line32"></a>goog.proto2.Metadata;
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>
<a name="line36"></a>/**
<a name="line37"></a> * A class which describes a Protocol Buffer 2 Message.
<a name="line38"></a> *
<a name="line39"></a> * @param {function(new:goog.proto2.Message)} messageType Constructor for
<a name="line40"></a> *      the message class that this descriptor describes.
<a name="line41"></a> * @param {!goog.proto2.Metadata} metadata The metadata about the message that
<a name="line42"></a> *      will be used to construct this descriptor.
<a name="line43"></a> * @param {Array.&lt;!goog.proto2.FieldDescriptor&gt;} fields The fields of the
<a name="line44"></a> *      message described by this descriptor.
<a name="line45"></a> *
<a name="line46"></a> * @constructor
<a name="line47"></a> */
<a name="line48"></a>goog.proto2.Descriptor = function(messageType, metadata, fields) {
<a name="line49"></a>
<a name="line50"></a>  /**
<a name="line51"></a>   * @type {function(new:goog.proto2.Message)}
<a name="line52"></a>   * @private
<a name="line53"></a>   */
<a name="line54"></a>  this.messageType_ = messageType;
<a name="line55"></a>
<a name="line56"></a>  /**
<a name="line57"></a>   * @type {?string}
<a name="line58"></a>   * @private
<a name="line59"></a>   */
<a name="line60"></a>  this.name_ = metadata.name || null;
<a name="line61"></a>
<a name="line62"></a>  /**
<a name="line63"></a>   * @type {?string}
<a name="line64"></a>   * @private
<a name="line65"></a>   */
<a name="line66"></a>  this.fullName_ = metadata.fullName || null;
<a name="line67"></a>
<a name="line68"></a>  /**
<a name="line69"></a>   * @type {goog.proto2.Message|undefined}
<a name="line70"></a>   * @private
<a name="line71"></a>   */
<a name="line72"></a>  this.containingType_ = metadata.containingType;
<a name="line73"></a>
<a name="line74"></a>  /**
<a name="line75"></a>   * The fields of the message described by this descriptor.
<a name="line76"></a>   * @type {!Object.&lt;number, !goog.proto2.FieldDescriptor&gt;}
<a name="line77"></a>   * @private
<a name="line78"></a>   */
<a name="line79"></a>  this.fields_ = {};
<a name="line80"></a>
<a name="line81"></a>  for (var i = 0; i &lt; fields.length; i++) {
<a name="line82"></a>    var field = fields[i];
<a name="line83"></a>    this.fields_[field.getTag()] = field;
<a name="line84"></a>  }
<a name="line85"></a>};
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * Returns the name of the message, if any.
<a name="line90"></a> *
<a name="line91"></a> * @return {?string} The name.
<a name="line92"></a> */
<a name="line93"></a>goog.proto2.Descriptor.prototype.getName = function() {
<a name="line94"></a>  return this.name_;
<a name="line95"></a>};
<a name="line96"></a>
<a name="line97"></a>
<a name="line98"></a>/**
<a name="line99"></a> * Returns the full name of the message, if any.
<a name="line100"></a> *
<a name="line101"></a> * @return {?string} The name.
<a name="line102"></a> */
<a name="line103"></a>goog.proto2.Descriptor.prototype.getFullName = function() {
<a name="line104"></a>  return this.fullName_;
<a name="line105"></a>};
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * Returns the descriptor of the containing message type or null if none.
<a name="line110"></a> *
<a name="line111"></a> * @return {goog.proto2.Descriptor} The descriptor.
<a name="line112"></a> */
<a name="line113"></a>goog.proto2.Descriptor.prototype.getContainingType = function() {
<a name="line114"></a>  if (!this.containingType_) {
<a name="line115"></a>    return null;
<a name="line116"></a>  }
<a name="line117"></a>
<a name="line118"></a>  return this.containingType_.getDescriptor();
<a name="line119"></a>};
<a name="line120"></a>
<a name="line121"></a>
<a name="line122"></a>/**
<a name="line123"></a> * Returns the fields in the message described by this descriptor ordered by
<a name="line124"></a> * tag.
<a name="line125"></a> *
<a name="line126"></a> * @return {!Array.&lt;!goog.proto2.FieldDescriptor&gt;} The array of field
<a name="line127"></a> *     descriptors.
<a name="line128"></a> */
<a name="line129"></a>goog.proto2.Descriptor.prototype.getFields = function() {
<a name="line130"></a>  /**
<a name="line131"></a>   * @param {!goog.proto2.FieldDescriptor} fieldA First field.
<a name="line132"></a>   * @param {!goog.proto2.FieldDescriptor} fieldB Second field.
<a name="line133"></a>   * @return {number} Negative if fieldA&#39;s tag number is smaller, positive
<a name="line134"></a>   *     if greater, zero if the same.
<a name="line135"></a>   */
<a name="line136"></a>  function tagComparator(fieldA, fieldB) {
<a name="line137"></a>    return fieldA.getTag() - fieldB.getTag();
<a name="line138"></a>  };
<a name="line139"></a>
<a name="line140"></a>  var fields = goog.object.getValues(this.fields_);
<a name="line141"></a>  goog.array.sort(fields, tagComparator);
<a name="line142"></a>
<a name="line143"></a>  return fields;
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * Returns the fields in the message as a key/value map, where the key is
<a name="line149"></a> * the tag number of the field. DO NOT MODIFY THE RETURNED OBJECT. We return
<a name="line150"></a> * the actual, internal, fields map for performance reasons, and changing the
<a name="line151"></a> * map can result in undefined behavior of this library.
<a name="line152"></a> *
<a name="line153"></a> * @return {!Object.&lt;number, !goog.proto2.FieldDescriptor&gt;} The field map.
<a name="line154"></a> */
<a name="line155"></a>goog.proto2.Descriptor.prototype.getFieldsMap = function() {
<a name="line156"></a>  return this.fields_;
<a name="line157"></a>};
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>/**
<a name="line161"></a> * Returns the field matching the given name, if any. Note that
<a name="line162"></a> * this method searches over the *original* name of the field,
<a name="line163"></a> * not the camelCase version.
<a name="line164"></a> *
<a name="line165"></a> * @param {string} name The field name for which to search.
<a name="line166"></a> *
<a name="line167"></a> * @return {goog.proto2.FieldDescriptor} The field found, if any.
<a name="line168"></a> */
<a name="line169"></a>goog.proto2.Descriptor.prototype.findFieldByName = function(name) {
<a name="line170"></a>  var valueFound = goog.object.findValue(this.fields_,
<a name="line171"></a>      function(field, key, obj) {
<a name="line172"></a>        return field.getName() == name;
<a name="line173"></a>      });
<a name="line174"></a>
<a name="line175"></a>  return /** @type {goog.proto2.FieldDescriptor} */ (valueFound) || null;
<a name="line176"></a>};
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * Returns the field matching the given tag number, if any.
<a name="line181"></a> *
<a name="line182"></a> * @param {number|string} tag The field tag number for which to search.
<a name="line183"></a> *
<a name="line184"></a> * @return {goog.proto2.FieldDescriptor} The field found, if any.
<a name="line185"></a> */
<a name="line186"></a>goog.proto2.Descriptor.prototype.findFieldByTag = function(tag) {
<a name="line187"></a>  goog.proto2.Util.assert(goog.string.isNumeric(tag));
<a name="line188"></a>  return this.fields_[parseInt(tag, 10)] || null;
<a name="line189"></a>};
<a name="line190"></a>
<a name="line191"></a>
<a name="line192"></a>/**
<a name="line193"></a> * Creates an instance of the message type that this descriptor
<a name="line194"></a> * describes.
<a name="line195"></a> *
<a name="line196"></a> * @return {!goog.proto2.Message} The instance of the message.
<a name="line197"></a> */
<a name="line198"></a>goog.proto2.Descriptor.prototype.createMessageInstance = function() {
<a name="line199"></a>  return new this.messageType_;
<a name="line200"></a>};
</pre>


</body>
</html>
